<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Usersession
{
    protected static $_instance = NULL;
    private $session; 
    
//===============================Закрываем конструктор==========================
    private function __construct() 
    {
        session_start();
        $_SESSION['session_id'] = '0';
        $_SESSION['ip_address'] = $_SERVER['SERVER_ADDR'];
        $_SESSION['user_agent']= $_SERVER['HTTP_USER_AGENT'];
        $this->session = $_SESSION;
    }
    
//===============================Запрещаем клонирование=========================    
    private function __clone() 
    {
    }
    
//===============================Создаём инстанс================================    
    static function getInstance()
    {
      if (self::$_instance == NULL)
      {
        self::$_instance = new Usersession();
      }
      return self::$_instance;
    }
    
//=========================Устанавливаем пользовательские данные сессии=========    
    public function setUserData( $id, $arr_userdata)
    {
        $_SESSION['session_id'] = sha1($id);
        $_SESSION['userdata'] = $arr_userdata;
        $this->session = $_SESSION;
        return  $this->session;
    }

//===============================Возврат данных сессии==========================    
    public function getSession()
    {
        return $this->session;
    }
    
//===============================Удаление сессии================================    
    static function destruct()
    {
        self::$_instance = NULL;
        session_destroy();
    }
}
?>
